package com.cpp.server.tools;

import cn.hutool.core.bean.BeanUtil;
import com.cpp.pojo.dto.aiTool.ChapterToolDTO;
import com.cpp.pojo.dto.aiTool.KnowledgeToolDTO;
import com.cpp.pojo.dto.aiTool.QuestionEasyToolDTO;
import com.cpp.pojo.pojo.Chapter;
import com.cpp.pojo.pojo.Knowledge;
import com.cpp.pojo.pojo.Question;
import com.cpp.server.mapper.ChapterMapper;
import com.cpp.server.mapper.KnowledgeMapper;
import com.cpp.server.mapper.QuestionMapper;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.ai.tool.annotation.ToolParam;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@RequiredArgsConstructor
@Slf4j
@Component
//@Data
public class GeneratePptTool {
    //    可以调用工具存储知识讲解，实训练习
    private final ChapterMapper chapterMapper;
    private final KnowledgeMapper knowledgeMapper;
    private final QuestionMapper questionMapper;
    //    private final PptGenerationClient pptGenerationClient;
//    private List<Knowledge> knowledges =new ArrayList<>();
//    private List<Chapter> chapters =new ArrayList<>();
//    private List<Question> questions =new ArrayList<>();




    @Tool(description = "批量保存章节,返回章节id")
    public List<Chapter> saveChapter(
//            @ToolParam(description = "课程id")Long courseId,
//            @ToolParam(description = "章节标题")String title,
//            @ToolParam(description = "章节内容简介")String content,
//            @ToolParam(description = "预计学习时长（分钟）")Integer duration,
//            @ToolParam(description = "章节排序（这个章节是这个课程的第几节）")Integer sort
            @ToolParam(description = "章节列表") List<ChapterToolDTO> chapterToolDTOs
    ){
        //数据准备
        List<Chapter> chapter = new ArrayList<>();
        chapter.addAll(BeanUtil.copyToList(chapterToolDTOs, Chapter.class));
        //插入章节，获得id
        chapterMapper.insert(chapter);
//        chapters.addAll(chapter);
        log.info("存储章节:{}",chapter);

        return chapter;
    }
    @Tool(description = "批量保存知识讲解,返回知识点id")
    public List<Knowledge> saveKnowledge(
//            @ToolParam(description = "课程id")Long courseId,
//            @ToolParam(description = "知识点名字" )String name,
//            @ToolParam(description = "知识点内容")String content
            @ToolParam(description = "知识点列表") List<KnowledgeToolDTO> knowledgeToolDTOs
    ) {
        List<Knowledge> knowledge = new ArrayList<>();
        knowledge.addAll(BeanUtil.copyToList(knowledgeToolDTOs, Knowledge.class));
        //插入知识点
        knowledgeMapper.insert(knowledge);
        //携带id方便更新
//        knowledges.addAll(knowledge);
        log.info("存储知识点:{}",knowledge);
        return knowledge;
    }
    @Tool(description = "批量保存实训练习")
    public void saveQuestion(
//            @ToolParam(description = "知识点id")Long knowledgeId,
//            @ToolParam(description = "题目")String content,
//            @ToolParam(description = "答案")String answer,
//            @ToolParam(description = "答案解析")String analysis,
//            @ToolParam(description = "课程id")Long courseId
            @ToolParam(description = "题目列表") List<QuestionEasyToolDTO> questionToolDTOs
    ) {
        List<Question> question = new ArrayList<>();
        question.addAll(BeanUtil.copyToList(questionToolDTOs, Question.class));
//        Question question = Question.builder()
//                .courseId(courseId)
//                .knowledgeIds(String.valueOf(knowledgeId))
//                .content(content)
//                .answer(answer)
//                .analysis(analysis)
//                .difficulty(QuestionHardT ype.EASY.getType())//默认简单
//                .type(QuestionType.SHORT_ANSWER.getType())//默认简答题
//                .build();

        questionMapper.insert(question);
//        questions.addAll(question);
        log.info("存储实训练习:{}",question);
    }
    boolean isClearOne =false;
    boolean isClearTwo =false;


}
